<?php
class Controller
{
	protected $wbClient = NULL;
	public $login_user = FALSE;
	public $tpl = NULL;
	public function __construct()
	{
		$this->tpl = Util::getTpl();
		$this->login_user = $this->IsLogin();
		$this->assign('login_user', $this->login_user);
	}
	
	public function assign($var, $val)
	{
		$this->tpl->assign($var, $val);
	}
	
	public function display($tpl_name)
	{
		$this->tpl->display($tpl_name);
	}
	
	public function Index()
	{
		echo '404';
	}
	
	public function IsLogin()
	{
		$cookies = Util::getCookies('last_key');
		if ($cookies){
			$wbClient = new SaeTClient(Config::$WB_AKEY, 
				Config::$WB_SKEY, 
				$cookies['oauth_token'],
				$cookies['oauth_token_secret']
			);
			$this->wbClient = $wbClient;
			$userInfo = $this->wbClient->verify_credentials($cookies['user_id']);
			if ($userInfo)
				return $userInfo;
		}
		return false;
	}
	
	public function __call($name, $arguments)
	{
		exit('Access Forbidden!');
	}
	
	public function __get($name)
	{
		exit('Access Forbidden!');
	}
	
}